package de.duplicatedetector.init.language;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;


public class LanguagePack {
	
	private Language currentLanguage;
	private HashMap<String, Language> languages;
	private Properties properties;
	
	public LanguagePack() {
		languages = new HashMap<String, Language>();
		currentLanguage = null;
		properties = new Properties();
	}
	
	public void setCurrentLanguage(String key) {
		if(languages.containsKey(key)) {
			System.out.println("test");
			currentLanguage = languages.get(key);
		}
	}
	
	public Language getCurrentLanguage() {
		return currentLanguage;
	}
	
	public void addLanguage(Language language) {
		System.out.println(language.getName().split("\\.")[0]);
		languages.put(language.getName().split("\\.")[0], language);
	}
	
	public void removeLanguage(Language language) {
		languages.remove(language);
	}
	
	public void load() {
		if(currentLanguage != null) {
			try {
				properties.load(new FileInputStream(currentLanguage));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public void getLoadedLanguageProperties() {
		Set<Entry<Object, Object>> entries = properties.entrySet();
		for(Entry<Object, Object> entry : entries) {
			System.out.println(entry.getKey().toString() + " " + entry.getValue().toString());
		}
	}
}

